This tutorial shows how to read Property from application.properties from HTML.
Syntax
<p th:text="${@environment.getProperty('messages.hello')}"/>
Application Schema [Results]
Spring Boot Starters
Create Project: properties_read_fromhtml (add Spring Boot Starters from the table)
Edit File: application.properties (inside src/main/resources)
Create Package: controllers (inside package com.ivoronline.test_spring_boot)
– Create Class: MyController.java (inside package controllers)
Create HTML File: Test.html (inside directory resources/templates)
application.properties
messages.hello = Hello from Controller
MyController.java
package com.ivoronline.properties_read_fromhtml.controllers;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
@Controller
public class MyController {
@RequestMapping("/Hello")
public String hello() {
System.out.println("Hello from Controller");
return "Test";
}
}
Test.html
<title>Test.html</title>
<p th:text="${@environment.getProperty('messages.hello')}"/>
<form th:attr="action=${@environment.getProperty('form.action')}" method="get"/>